package Day8Zuoye;

import java.io.*;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class WeatherLogin extends Thread {
    private final Socket s;

    private static List<Listinfo> list=new ArrayList();
    static{
      list.add(new Listinfo("1-17℃","2级","24","46%"));
    }
    public WeatherLogin(Socket s){
        this.s=s;
    }

    @Override
    public void run() {
        System.out.println("socket连接建立了。。。" + s);
        try {
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            PrintWriter pw = new PrintWriter(out, true);
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            Date date=new Date();
            String time=sdf.format(date.getTime());
            String info=br.readLine();
            Listinfo listinfo=new Listinfo();
            if(info.equals("气温")){
                pw.println(listinfo.getAirtemperature()+"\t"+time);
            }else if(info.equals("风力")){
                pw.println(listinfo.getWindpower()+"\t"+time);
            }else if(info.equals("pm2.5")){
                pw.println(listinfo.getPm2d5()+"\t"+time);
            }else if(info.equals("湿度")){
                pw.println(listinfo.getHumidity()+"\t"+time);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                s.close();
                System.out.println(s+"关闭了。。。聊天结束");
            } catch (Exception e) {

            }
        }
    }
}

